package discount;

import DiscountEnum.FullReductionEnum;
import impl.Calculate;

/**
 * 满减优惠计算
 */
public class OperationFullReduction implements Calculate {
    /**
     *
     * @param price 价格
     * @param EnumValue 满减枚举
     * @return 优惠后价格
     */
    @Override
    public double CalculateFruit(Double price, Enum<?> EnumValue) {
        if (EnumValue != null && EnumValue.name().contains("FullReduction_")) {
            FullReductionEnum fullReductionEnum = (FullReductionEnum) EnumValue;
            if (price >= fullReductionEnum.getTotalPrice()) {
                return price - fullReductionEnum.getDiscount();
            }
        }
        return price;
    }
}
